package com.example.baseadapter;




import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.Toast;

public class AddCase extends ActionBarActivity {
	EditText plaintiff, respondent, caseRefno, caseDetail, courtDetail;
 
   DatabaseHelper db;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	
		db=new DatabaseHelper(getApplicationContext());
		
		//setting action bar background color
       getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.rgb(10,132,132)));
		
        // Enabling Up / Back navigation
       getSupportActionBar().setDisplayHomeAsUpEnabled(true);
       getSupportActionBar().setHomeButtonEnabled(true);
		getWindow().setSoftInputMode(
			    WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
			);
		
		setContentView(R.layout.add_case);

		plaintiff = (EditText) findViewById(R.id.editText1);
		respondent = (EditText) findViewById(R.id.editText2);
		caseRefno = (EditText) findViewById(R.id.editText3);
		caseDetail = (EditText) findViewById(R.id.editText4);
		courtDetail= (EditText) findViewById(R.id.editText5);
		
		
		
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.add_case_actionbar, menu);

		return super.onCreateOptionsMenu(menu);
	}

	/**
	 * On selecting action bar icons
	 * */
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		

		// Take appropriate action for each action item click
		switch (item.getItemId()) {
		case R.id.action_save:
			// adding new icon in the action bar
			saveCase();
			return true;

		default:
			return super.onOptionsItemSelected(item);
		}

	}
	public  void saveCase() {
		Case caseObj = new Case();
		  caseObj.setPlaintiff(plaintiff.getText().toString());
		  caseObj.setRespondent(respondent.getText().toString());
		  caseObj.setCaseRefno(caseRefno.getText().toString());
		  caseObj.setCaseDetail(caseDetail.getText().toString());
	      caseObj.setCourtDetail(courtDetail.getText().toString());
	      long id1=db.createCase(caseObj);
	      Toast.makeText(this,"Your case has been saved successfully.",Toast.LENGTH_LONG).show();
	      Log.e("Case Count", "Case count: " + db.getCaseCount());
	      Intent intent=new Intent(this,MainActivity.class);
			startActivity(intent);
		
	}
	//this is done to disable back press.
	@Override
	public void onBackPressed()
	{
		
	}
	
	
}
